﻿using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.Instances;

namespace NHibernate.Sidekick.Utils.MappingConventions
{
    ///<summary>
    /// Cascade underlying changes from the domain object.
    ///</summary>
    public class CascadeAllConvention : IHasOneConvention, IHasManyConvention, IReferenceConvention
    {
        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IOneToOneInstance instance)
        {
            instance.Cascade.All();
        }

        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IOneToManyCollectionInstance instance)
        {
            instance.Cascade.All();
        }

        /// <summary>
        /// Apply changes to the target.
        /// </summary>
        /// <param name="instance"></param>
        public void Apply(IManyToOneInstance instance)
        {
            instance.Cascade.All();
        }
    }
}